<?php

namespace addons\shop\controller;


use addons\shop\model\Category;
use addons\shop\model\Goods;

/**
 * 店铺
 * Class Store
 * @package addons\shop\controller
 */
class Store extends Base
{
    protected $noNeedLogin = ['list', 'detail','products'];


    /**
     * 店铺列表
     */
    public function list()
    {
        $categories = Category::where('status', 'normal')
            ->order('weigh desc,id desc')
            ->cache(true)
            ->select();
        $this->assign("categories",$categories);
        $this->view->assign('goodsList', Goods::getIndexGoodsList(4));
        return $this->view->fetch('/stores');
    }


    /**
     * 店铺详情
     */
    public function detail() {
        $store = [
            "id" => $this->request->param("id")
        ];
        $this->view->assign('goodsList', Goods::getIndexGoodsList());
        $this->view->assign('hotGoodsList', array_reverse(Goods::getIndexGoodsList(4)));
        $this->view->assign('recommendGoodsList', array_slice(array_reverse(Goods::getIndexGoodsList()),0,4));
        $this->view->assign("store",$store);
        return $this->view->fetch('/store');
    }

    /**
     * 店铺商品列表
     */
    public function products() {
        $this->view->assign('goodsList', Goods::getIndexGoodsList());
        return $this->view->fetch('/store_products');
    }

}
